import json

from pyecharts import options
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts, ToolboxOpts

r=open("F:/Python/res/疫情.txt", "r", encoding="utf-8")
data=r.read()

data_dict=json.loads(data)

data_all_province=data_dict["areaTree"][0]["children"]

shandong_province_data=data_all_province[11]["children"]

city_data_list=[]
for city in shandong_province_data:
    city_name=city["name"]+"市"
    city_confirm=city["total"]["confirm"]
    city_data_list.append((city_name,city_confirm))

del city_data_list[0]

map=Map(init_opts=options.InitOpts(width="1200px", height="600px"))

map.add("山东省疫情地图",city_data_list,"山东")

map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#30f33d"},
            {"min": 10, "max": 99, "label": "1-99人", "color": "#8ab90e"},
            {"min": 100, "max": 499, "label": "100-499人", "color": "#faf733"},
            {"min": 500, "max": 999, "label": "500-999人", "color": "#fa9f33"},
            {"min": 1000, "max": 1999, "label": "1000-1999人", "color": "#fa5533"}

        ]
    ),
toolbox_opts = ToolboxOpts(
    is_show=True,  # 是否显示工具箱
    pos_right="80%",  # 位置
    pos_top="10%",
    orient="vertical",
    feature=options.ToolBoxFeatureOpts(
        save_as_image=options.ToolBoxFeatureSaveAsImageOpts(  # 保存为图片
            title="保存为图片",
            pixel_ratio=2
        ),
        restore=options.ToolBoxFeatureRestoreOpts(title="重置"),  # 重置
        magic_type=options.ToolBoxFeatureMagicTypeOpts(  # 动态类型切换
            type_=["line", "bar"]
        )
    )
)
)

map.render("shandong_pandemic_map.html")





map=Map(init_opts=options.InitOpts(width="1200px", height="600px"))